var route_prefix = '/app_dev.php';
//var route_prefix = '/app.php';
//var route_prefix = '';

//RemoteDataURLs
var remote_data_urls = 
{
    'is_set_in_database': route_prefix + '/remote_data/is_set_in_database'
};

/**
 * Checks if dataset already exists in the database
 * 
 * @param string entity_name name of the entity
 * @param string entity_properties has to be in the json format '{"key1" : "value1", "key2" : "value2", ...}'
 * @param function callback called after ajax success. Has to accept boolen parameter
 */
function existsEntity(entity_name, entity_properties, callback)
{
    $.ajax
    ({
        type: "POST",
        dataType: "text",
        data: {entity : entity_name, properties : entity_properties},
        url: remote_data_urls.is_set_in_database,
        cache: false,
        success: function(response)
        {
            if(response=='1')
                callback(true);
            else
                callback(false);
        }
    });
}

/**
 * Fetches a resource(rendered HTML)
 * 
 * @param string resource_url location of the resource
 * @param object params_obj javascript object containing additional parameter
 * @param function callback called after ajax success. Passes the fetched resource
 */
function getResource(resource_url, callback, params_obj)
{
    if(typeof(params_obj)=='object')
    {
        $.ajax
        ({
            type: "POST",
            dataType: "text",
            data: params_obj,
            url: resource_url,
            cache: false,
            success: function(response)
            {
                callback(response);
            }
        });
    }
    else
    {
        $.ajax
        ({
            type: "POST",
            dataType: "text",
            url: resource_url,
            cache: false,
            success: function(response)
            {
                callback(response);
            }
        });
    }
}
